
<script>
function searchProducts() {
  // 获取搜索关键词
  const input = document.getElementById('searchInput');
  const searchTerm = input.value.trim().toLowerCase();

  // 获取所有商品
  const products = document.querySelectorAll('.product-item');

  // 遍历商品进行筛选
  products.forEach(product => {
    const productName = product.dataset.name.toLowerCase();
    if (productName.includes(searchTerm)) {
      product.classList.remove('hidden');
    } else {
      product.classList.add('hidden');
    }
  });
}

// 添加回车键支持
document.getElementById('searchInput').addEventListener('keypress', function(e) {
  if (e.key === 'Enter') {
    searchProducts();
  }
});
</script>